package ir.values.users;

import frontend.visitor.symboltbl.scope.Scope;
import ir.types.Type;
import ir.types.datatypes.PointerType;
import ir.values.users.constants.Constant;

public class GlobalVariable extends User {
    private final boolean isConst;
    private final Constant initializer;

    public GlobalVariable(String originalName, Constant initializer, boolean isConst) {
        super(originalName, new PointerType(initializer.getDataType()));
        this.initializer = initializer;
        this.isConst = isConst;
        operands.add(initializer);
    }
    @Override
    public String parseUsingName() {
        return "@" + originalName;
    }
    @Override
    public String parseLLVM() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("@")
                .append(originalName)
                .append(" = dso_local ")
                .append(isConst ? "constant" : "global")
                .append(" ")
                .append(initializer.parseLLVM())
                .append("\n");
        return sb.toString();
    }
}
